<?php

namespace app\admin\validate\goods;

use think\Validate;

class GoodsActive extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'price' => 'require|float|egt:0',
        'original_price' => 'require|float|egt:0',
        'goods_no'=>'require|unique:goods,goods_no',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'price.require' => '活动费用不能为空',
        'price.egt' => '活动费用必须大于等于0',
        'original_price.require' => '活动成本不能为空',
        'original_price.egt' => '活动成本必须大于等于0',
        'goods_no.require' => '唯一编码不能为空',
        'goods_no.unique' => '唯一编码已存在',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['price','original_price','commission_price','goods_no'],
        'edit' => ['price','original_price','commission_price','goods_no'],
    ];


    public function __construct(array $rule = [], array $message = [], array $field = [])
    {
        parent::__construct($rule, $message, $field);
        $ids = request()->param("ids");
        if ($ids) {
            $this->rule['goods_no'] = 'require|unique:goods,goods_no,' . $ids . ',id';
        }
    }
    
}
